<?php

namespace App\Http\Middleware;

use Closure;
use App\Models\User;

class CheckPayInfo
{
    /**
     * Handle an incoming request.
     * 验证是否绑定支付信息中间件
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //如果有uid参数
        if ($request->has('uid')) {
            //用户 ID
            $uid = $request->get('uid');
            //查找用户
            $user = User::find($uid);
            //验证用户是否存在
            if (count($user) == 0) {
                //用户不存在
                return respF(1001);
            }
            //判断是否绑定支付信息
            if (count($user->user_alipay) == 0 && count($user->user_wechat) == 0) {
                //请绑定至少一种支付方式
                return respF(3016);
            }
        }

        return $next($request);
    }
}
